<template>
  <el-form :model="data" ref="form" :rules="rules" class="form">
    <el-form-item label="所属分类" :label-width="formLabelWidth">
      <el-input :disabled="true" v-model="categoryName"></el-input>
    </el-form-item>
    <el-form-item label="商品名称" prop="name" :label-width="formLabelWidth">
      <el-input v-model="data.name" placeholder="请输入商品名称"></el-input>
    </el-form-item>
    <el-form-item label="商品标题" prop="title" :label-width="formLabelWidth">
      <el-input v-model="data.title" placeholder="请输入商品标题"></el-input>
    </el-form-item>
  </el-form>
</template>

<script>
import productFormMixins from "@/views/base/productForm";
import jsonUtils from "@/utils/jsonUtils";

export default {
  name: "spuUpdateBaseForm",
  props: ["categoryName", "spuInfo"],
  mixins: [productFormMixins],
  data() {
    return {
      init: {
        name: "11",
        title: "11",
      },
      data: {
        name: "11",
        title: "11",
      },
      rules: {
        name: [
          {
            required: true,
            message: "请输入名称",
            trigger: "blur",
          },
          {
            min: 2,
            max: 20,
            message: "长度在 2 到 20 之间",
            trigger: "blur",
          },
        ],
        title: [
          {
            required: true,
            message: "请输入标题",
            trigger: "blur",
          },
          {
            min: 2,
            max: 200,
            message: "长度在 2 到 200 之间",
            trigger: "blur",
          },
        ],
      },
    };
  },
  methods: {
    initData() {
      if (this.spuInfo.info) {
        this.data = jsonUtils.deepCopy(this.spuInfo.info);
      }
    },
    getPreviewData() {
      return { ...this.data,  categoryName: this.categoryName };
    },
  },
};
</script>

<style lang="less" scoped>
.form {
  overflow: auto;
  height: 60vh;
}
</style>